from django.shortcuts import render
from django.shortcuts import render_to_response
from django.shortcuts import HttpResponse
from models import Question

# Create your views here.

def hello(request):
    return render_to_response('2.html')

def index(request):
    ls_q = Question.objects.order_by('-pub_date')[:5]
    return render(request, 'djtest/index.html', {'q_ls': ls_q})

def detail(request, question_id):
    try:
        question = Question.objects.get(pk=question_id)
    except Question.DoesNotExist:
        raise Http404('Question does not exist!')

    return render(request, 'djtest/detail.html', {'question': question, 'choices': question.choice_set.all()})

def results(request, question_id):
    return HttpResponse('results of %s.'% question_id)

def vote(request, question_id):
    return HttpResponse('U have voted to %s.' % question_id)

